﻿using System;
using System.Configuration;

namespace Nana.Web.Compressing
{
  public sealed class FactoryTypeValidator
    : ConfigurationValidatorBase
  {
    internal static readonly Type typeType = typeof(Type);
    internal static readonly Type typeFactory = typeof(ResponseFilterFactory);

    public override bool CanValidate(Type type)
    {
      return typeType == type;
    }
    public override void Validate(object value)
    {
      if (!typeFactory.IsAssignableFrom(value as Type))
        throw new ArgumentOutOfRangeException();
    }
  }

  [AttributeUsage(AttributeTargets.Property)]
  public sealed class FactoryTypeValidatorAttribute
    : ConfigurationValidatorAttribute
  {
    public override ConfigurationValidatorBase ValidatorInstance
    {
      get
      {
        return new FactoryTypeValidator();
      }
    }
  }

}
